const center = require('../pkg/unmp_center_wasm');

const myid = new Uint8Array([0x84, 0x12, 0x01, 0x02, 0x05]);
const private_key = new Uint8Array([202, 239, 123, 108, 182, 66, 137, 226]);
const public_key = new Uint8Array([79, 171, 204, 102, 2, 80, 179, 247]);
const product_id = BigInt(258);
const product_key = new Uint8Array([0xc8, 0x33, 0x97, 0x7a, 0x7b, 0x16, 0x0b, 0xac]);

center
  .init(myid)
  .then(() => {
    center
      .login(myid, private_key)
      .then(() => {
        console.log('login.');
        setInterval(() => {
          center.heart().catch((err) => {
            console.log(err);
          });
        }, 30000);
        center.set_actual(myid, public_key, 0x8001, new Uint8Array([0x03])).catch((err) => {
          console.log(err);
        });
      })
      .catch((err) => {
        console.log(err);
      });
  })
  .catch((err) => {
    console.log(err);
  });

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection at:', p, 'reason:', reason);
  // application specific logging, throwing an error, or other logic here
});
